package com.vint.leetcode;

import com.vint.common.TreeNode;

/*
 * 1. done
 * 2. easy
 * 3. tree, 递归
 * 求树的minDepth,指
 */
public class Leetcode111 {
    public int minDepth(TreeNode root) {
        if(null==root)return 0;
        if(null==root.right&&null==root.left)return 1;
        if(null==root.left)return minDepth(root.right)+1;
        if(null==root.right)return minDepth(root.left)+1;
        return 1+Math.min(minDepth(root.left),minDepth(root.right));

    }
    public static void main(String[] args) {
        Leetcode111 leetcode101= new Leetcode111();
        TreeNode root = new TreeNode(1);
        root.left = new TreeNode(2);
        root.left.left = new TreeNode(5);
        root.right = new TreeNode(4);
        //root.right.right= new TreeNode(2);
        System.out.println(leetcode101.minDepth(root));
    }
  }
